<template>
    <view class="welcome">
        <view class="wxheader">
            <view class="wxImage">
                <open-data type="userAvatarUrl"></open-data>
            </view>
            <view class="wxName">
                <open-data type="userNickName"></open-data>
            </view>
        </view>
        <view class="wxbody">
            <uni-list>
                <uni-list-item v-for="(item,index) in infos" :key="item.key" v-if="item.key"
                    :title="item.chineseKey || item.key" :rightText="item.value">
                </uni-list-item>
            </uni-list>
        </view>
    </view>
</template>

<script>
    import myServer from '@/plugins/http/server/my'
    import { appkey, chinens } from '@/assets/config'
    const { getCustomerInfo } = myServer
    const noShows = ['uniId','phone']
    export default {
        data() {
            return {
                infos: []
            }
        },
        methods: {
            getData() {
                const { wechatInfo } = this.$store.state
                const { phone } = wechatInfo
                const infoParams = {
                    appkey,
                    mobile: phone,
                    platCode: 'weixin'
                }
                getCustomerInfo(infoParams).then(res => {
                    const obj = JSON.parse(res.data)
                    this.infos = Object.keys(obj).map(key => {
                        if (!noShows.includes(key)) {
                            return {
                                key,
                                chineseKey: chinens.filter(c => c.key === key)[0]?.chineseKey,
                                value: obj[key] || '--'
                            }
                        }
                    })
                }).catch(e => {
                    console.log(e)
                })
            }
        },
        mounted() {
            this.getData()
        }
    }
</script>

<style lang="less" scoped>
    @import 'index';
</style>
